package com.acg.service.impl;

import com.acg.entity.OrderItem;
import com.acg.dao.OrderItemDao;
import com.acg.service.OrderItemService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import jakarta.annotation.Resource;
import java.util.*;
/**
 * 订单详情表(OrderItem)表服务实现类
 *
 * @author makejava
 * @since 2025-07-01 16:34:32
 */
@Service("orderItemService")
public class OrderItemServiceImpl implements OrderItemService {
    @Resource
    private OrderItemDao orderItemDao;

    /**
     * 通过ID查询单条数据
     *
     * @param orderItemId 主键
     * @return 实例对象
     */
    @Override
    public OrderItem queryById(Integer orderItemId) {
        return this.orderItemDao.queryById(orderItemId);
    }

    /**
     * 分页查询
     *
     * @param orderItem 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<OrderItem> queryByPage(OrderItem orderItem, PageRequest pageRequest) {
        long total = this.orderItemDao.count(orderItem);
        return new PageImpl<>(this.orderItemDao.queryAllByLimit(orderItem, pageRequest), pageRequest, total);
    }
    /**
    获取所有的数据
    */
    @Override
    public List<OrderItem> queryAll(){
        return  this.orderItemDao.queryAll();   
    }

    /**
     * 新增数据
     *
     * @param orderItem 实例对象
     * @return 实例对象
     */
    @Override
    public OrderItem insert(OrderItem orderItem) {
        this.orderItemDao.insert(orderItem);
        return orderItem;
    }

    /**
     * 修改数据
     *
     * @param orderItem 实例对象
     * @return 实例对象
     */
    @Override
    public OrderItem update(OrderItem orderItem) {
        this.orderItemDao.update(orderItem);
        return this.queryById(orderItem.getOrderItemId());
    }

    /**
     * 通过主键删除数据
     *
     * @param orderItemId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer orderItemId) {
        return this.orderItemDao.deleteById(orderItemId) > 0;
    }
}
